﻿Imports Cls_Common
Imports VSModel
Partial Class FrontEnd_Control_Home_BigBannerHome
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Bind2Repeater()
        End If
    End Sub

    Protected Sub Bind2Repeater()
        Using _data As New VSEntities
            Dim _LanguageId As Integer = Session("LanguageId")
            Dim p = (From q In _data.ImagesAdvers Where q.StatusID = 3 And q.Subject = ImageAdverType.BannerHome And q.LanguageID = _LanguageId Select q Order By q.Sort).ToList
            With rptImage
                .DataSource = p
                .DataBind()
            End With
            Dim _MenuId As Integer = ConfigurationManager.AppSettings("IdTinTuc_Vi")


            'xu ly ngon ngu
            Dim _lang As Integer = 1
            If Not Session("LanguageId") Is Nothing Then
                _lang = Session("LanguageId")

            End If
            If _lang = 2 Then
                lplTitleTinTuc.Text = "News - Event"
                _MenuId = ConfigurationManager.AppSettings("IdTinTuc_En") ' id tin tuc tieng anh
            End If

            Dim k = (From q In _data.Contents Where q.MenuId = _MenuId And q.StatusId = 3 And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() Or q.eEffectiveDate Is Nothing) Order By q.PublishedDate Descending
                     Select q).Take(10).ToList
            If k.Count > 0 Then
                If Not k(0) Is Nothing Then
                    hplTitle.Text = k(0).Title
                    hplTitle.NavigateUrl = MainDomain & k(0).MenuId.ToString & "/" & k(0).QueryString & "-" & k(0).Id.ToString & arrTypeLink(k(0).TypeId) & ".html"
                    imgImage.ImageUrl = CookedImageURL("76-76", k(0).Image.ToString)
                    hplImg.NavigateUrl = hplTitle.NavigateUrl
                End If
            End If

            rptShow.DataSource = k.Skip(1).Take(9)
            rptShow.DataBind()
            ' hplMore.NavigateUrl = MainDomain & "tin-tuc.html"

        End Using
    End Sub

    Protected Sub rptImage_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptImage.ItemDataBound
        Dim row As VSModel.ImagesAdver = CType(e.Item.DataItem, VSModel.ImagesAdver)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)

        hplTitle.NavigateUrl = row.URL
        Dim imgBig As Image = CType(e.Item.FindControl("imgBig"), Image)
        imgBig.ImageUrl = row.SRC
        imgBig.ToolTip = row.Title


    End Sub
    Protected Sub rptShow_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptShow.ItemDataBound
        '  hplTitle.NavigateUrl = MainDomain & "tin-tuc-chi-tiet/" & h.QueryString & "-" & h.Id.ToString & ".html"
        Dim row = CType(e.Item.DataItem, VSModel.Content)
        Dim img As Image = CType(e.Item.FindControl("imgImage"), Image)
        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)

        ' = CookedImageURL("80-80", row.Image.ToString)

        img.ImageUrl = MainDomain & "FrontEnd/images/arrow_news.png"
        hplTitle.Text = row.Title

        hplTitle.NavigateUrl = MainDomain & row.MenuId & "/" & row.QueryString & "-" & row.Id.ToString & arrTypeLink(row.TypeId) & ".html"
    End Sub

End Class
